using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Daemon.CSharp.Stages;
using JetBrains.ReSharper.Psi;
using Twins.Classes;
using Twins.Infrastructure;

namespace Twins.Daemon
{
    [DaemonStage]
    public class TwinsStage : CSharpDaemonStageBase
    {
        private DispatherProject project;

        public TwinsStage()
        {
            IoC.Initialize();
        }

        public DispatherProject Project
        {
            get { return project ?? (project = IoC.Resolve<DispatherProject>()); }
        }

        public override IDaemonStageProcess CreateProcess(IDaemonProcess process, DaemonProcessKind processKind)
        {
            if (!IsSupported(process.SourceFile))
                return null;
            Project.CreateFile(process.SourceFile);
            return new TwinsStageProcess(process, Project);
        }

        public override ErrorStripeRequest NeedsErrorStripe(IPsiSourceFile sourceFile)
        {
            if (!IsSupported(sourceFile))
                return ErrorStripeRequest.NONE;
            return ErrorStripeRequest.STRIPE_AND_ERRORS;
        }
    }
}